﻿using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using Blazing.BusinessObjects;
using Blazing.WebFacade;

namespace Blazing.Web.Controls
{
    public class SettingSnippetControl : Control
    {
        CmsManager _manager = null;
        public CmsManager Manager
        {
            get
            {
                if (_manager == null)
                    _manager = Blazing.Util.CmsManagerHelper.FindManagerObject(Page.Controls);
                if (_manager == null)
                    throw new ApplicationException("There was no active CmsManager object found on the current page.");
                return _manager;
            }
        }

        public string SettingKey { get; set; }

        protected override void  EnsureChildControls()
        {
 	         base.EnsureChildControls();

             Controls.Clear();
             if (Manager.SiteId != null)
             {
                Setting val = new SettingsController().GetSetting(Manager.SiteId.Value, SettingKey);
                if (val != null)
                {
                    Literal lit = new Literal();
                    lit.Text = val.Value;
                    Controls.Add(lit);
                }
            }  
        }
    }
}
